﻿from osc02.domain.activities.OnsiteActivity import OnsiteActivity


class Assembling(OnsiteActivity):
    def __init__(self, name, duration=None, lag=0,
                 duration_likely=20,
                 duration_low=10, duration_high=45,
                 completion_event=None,
                 # component_delivered_event=None,
                 worker_skill='1', worker_num=0,
                 crane_type=None,
                 component=None,
                 skd_delivery_time=None,
                 act_delivery_time=None,
                 act_erection_start=None,
                 act_duration=None
                 ):
        super().__init__(name, duration, lag, duration_likely, duration_low, duration_high, completion_event,
                         worker_skill, worker_num)
        self.crane_type = crane_type
        self.component = component
        self.skd_delivery_time = skd_delivery_time
        self.act_delivery_time = act_delivery_time
        self.act_erection_start = act_erection_start
        self.act_duration = act_duration
        self.component_delivered_event = None

    def __repr__(self):
        return super().__repr__() \
               + 'component=' + str(self.component) + ', '

    def act(self):
        print("Assembling act")
        crane = yield self.construction_site.crane.get(self, 'REQ CRN',
                                                       lambda item: self.crane_type in item.source_type)

        yield self.construction_site.env.timeout(self.duration)
        yield self.construction_site.crane.put(self, 'RLS CRN', crane)
        # release workers
        # print("@{now:.2f} {name} rls crn".format(now=self.construction_site.env.now,
        #                                          name=self.name,
        #                                          ))
